package com.yzy.classpool
{

	public class ClassPool
	{
		private var pool:Array=new Array(); 
		private var poolClass:IPoolClass;
		public function ClassPool(poolClass:IPoolClass)
		{
			this.poolClass=poolClass;
		}
		
		/**
		 * 获取对象  
		 * @return 
		 * 
		 */		
		public function getClass(t:*):*{
			if(pool.length>0){
				return pool.shift();
			}
			return new poolClass(t);
		}
		
		/**
		 * 归还对象 
		 * @param cls
		 * @return 
		 * 
		 */		
		public function returnClass(cls:IPoolClass):Boolean
		{
			var index:int=pool.indexOf(cls);
			if(index==-1){
				cls.reset();
				pool.push(cls);
				return true;
			}
			return false;	
		}
	}
}